﻿using System;
using FluentValidation;
using FluentValidation.TestHelper;
using GiveAQuizSite.Models;
using GiveAQuizSite.Validation;
using NUnit.Framework;

namespace GiveAQuizSite.Tests.Validation
{
  [TestFixture]
  public class LogOnValidatorTest
  {
    public IValidator<LogOnViewModel> Validator 
    {
      get; private set;
    }

    [TestFixtureSetUp]
    public void InitializeTest()
    {
      Validator = new LogOnValidator();
    }

    [Test]
    public void RuleFor_UserName_should_not_have_error_when_username_is_specified()
    {
      Validator.ShouldNotHaveValidationErrorFor(l => l.UserName, "Foo");
    }

    [Test]
    public void RuleFor_UserName_cannot_be_empty()
    {
      Validator.ShouldHaveValidationErrorFor(l => l.UserName, String.Empty);
    }

    [Test]
    public void RuleFor_UserName_cannot_be_null()
    {
      Validator.ShouldHaveValidationErrorFor(l => l.UserName, null as string);
    }

    [Test]
    public void RuleFor_UserName_cannot_be_blank()
    {
      Validator.ShouldHaveValidationErrorFor(l => l.UserName, "  ");
    }

    [Test]
    public void RuleFor_Password_should_not_have_error_when_username_is_specified()
    {
      Validator.ShouldNotHaveValidationErrorFor(l => l.Password, "Bar");
    }

    [Test]
    public void RuleFor_Password_cannot_be_empty()
    {
      Validator.ShouldHaveValidationErrorFor(l => l.Password, String.Empty);
    }

    [Test]
    public void RuleFor_Password_cannot_be_null()
    {
      Validator.ShouldHaveValidationErrorFor(l => l.Password, null as string);
    }

    [Test]
    public void RuleFor_Password_cannot_be_blank()
    {
      Validator.ShouldHaveValidationErrorFor(l => l.Password, "  ");
    }
  }
}
